package com.gdou.teaching.service.impl;

import com.gdou.teaching.Enum.UserStatusEnum;
import com.gdou.teaching.dataobject.User;
import com.gdou.teaching.dto.UserDTO;
import com.gdou.teaching.mapper.UserMapper;
import com.gdou.teaching.service.StudentService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author carrymaniac
 * @date Created in 14:16 2019-08-14
 * @description
 **/
@Service
public class StudentServiceImpl implements StudentService {

    @Autowired
    UserMapper userMapper;

    @Override
    public List<UserDTO> getUserByClassId(Integer classId) {
        List<User> userlist = userMapper.selectUserListByClassId(classId, UserStatusEnum.NORMAL.getCode());
        List<UserDTO> userDTOList = userlist.stream().map(user -> {
            UserDTO userDTO = new UserDTO();
            BeanUtils.copyProperties(user, userDTO);
            return userDTO;
        }).collect(Collectors.toList());
        return userDTOList;
    }




}
